Fix double-compression; fix missing deletion reason; fix html insertion attack; fix...
[lhc/web/wiklou.git] / includes / Article.php
1 <?
2 # Class representing a Wikipedia article and history.
3 # See design.doc for an overview.
4
5 # Note: edit user interface and cache support functions have been
6 # moved to separate EditPage and CacheManager classes.
7
8 /* CHECK MERGE @@@
9 TEST THIS @@@
10
11 * s/\$wgTitle/\$this->mTitle/ performed, many replacements
12 * mTitle variable added to class
13 */
14
15 include_once( "CacheManager.php" );
16
17 class Article {
18 /* private */ var $mContent, $mContentLoaded;
19 /* private */ var $mUser, $mTimestamp, $mUserText;
20 /* private */ var $mCounter, $mComment, $mCountAdjustment;
21 /* private */ var $mMinorEdit, $mRedirectedFrom;
22 /* private */ var $mTouched, $mFileCache, $mTitle;
23
24 function Article( &$title ) {
25 $this->mTitle =& $title;
26 $this->clear();
27 }
28
29 /* private */ function clear()
30 {
31 $this->mContentLoaded = false;
32 $this->mUser = $this->mCounter = -1; # Not loaded
33 $this->mRedirectedFrom = $this->mUserText =
34 $this->mTimestamp = $this->mComment = $this->mFileCache = "";
35 $this->mCountAdjustment = 0;
36 $this->mTouched = "19700101000000";
37 }
38
39 # Note that getContent/loadContent may follow redirects if
40 # not told otherwise, and so may cause a change to mTitle.
41
42 function getContent( $noredir = false )
43 {
44 global $action,$section,$count; # From query string
45 $fname = "Article::getContent";
46 wfProfileIn( $fname );
47
48 if ( 0 == $this->getID() ) {
49 if ( "edit" == $action ) {
50 wfProfileOut( $fname );
51 return ""; # was "newarticletext", now moved above the box)
52 }
53 wfProfileOut( $fname );
54 return wfMsg( "noarticletext" );
55 } else {
56 $this->loadContent( $noredir );
57
58 if(
59 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
60 ( $this->mTitle->getNamespace() == Namespace::getTalk( Namespace::getUser()) ) &&
61 preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$this->mTitle->getText()) &&
62 $action=="view"
63 )
64 {
65 wfProfileOut( $fname );
66 return $this->mContent . "\n" .wfMsg("anontalkpagetext"); }
67 else {
68 if($action=="edit") {
69 if($section!="") {
70 if($section=="new") {
71 wfProfileOut( $fname );
72 return "";
73 }
74
75 $secs=preg_split("/(^=+.*?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)/mi",
76 $this->mContent, -1,
77 PREG_SPLIT_DELIM_CAPTURE);
78 if($section==0) {
79 wfProfileOut( $fname );
80 return trim($secs[0]);
81 } else {
82 wfProfileOut( $fname );
83 return trim($secs[$section*2-1] . $secs[$section*2]);
84 }
85 }
86 }
87 wfProfileOut( $fname );
88 return $this->mContent;
89 }
90 }
91 }
92
93 function loadContent( $noredir = false )
94 {
95 global $wgOut, $wgMwRedir;
96 global $oldid, $redirect; # From query
97
98 if ( $this->mContentLoaded ) return;
99 $fname = "Article::loadContent";
100
101 # Pre-fill content with error message so that if something
102 # fails we'll have something telling us what we intended.
103
104 $t = $this->mTitle->getPrefixedText();
105 if ( isset( $oldid ) ) {
106 $oldid = IntVal( $oldid );
107 $t .= ",oldid={$oldid}";
108 }
109 if ( isset( $redirect ) ) {
110 $redirect = ($redirect == "no") ? "no" : "yes";
111 $t .= ",redirect={$redirect}";
112 }
113 $this->mContent = wfMsg( "missingarticle", $t );
114
115 if ( ! $oldid ) { # Retrieve current version
116 $id = $this->getID();
117 if ( 0 == $id ) return;
118
119 $sql = "SELECT " .
120 "cur_text,cur_timestamp,cur_user,cur_counter,cur_restrictions,cur_touched " .
121 "FROM cur WHERE cur_id={$id}";
122 wfDebug( "$sql\n" );
123 $res = wfQuery( $sql, DB_READ, $fname );
124 if ( 0 == wfNumRows( $res ) ) {
125 return;
126 }
127
128 $s = wfFetchObject( $res );
129 # If we got a redirect, follow it (unless we've been told
130 # not to by either the function parameter or the query
131 if ( ( "no" != $redirect ) && ( false == $noredir ) &&
132 ( $wgMwRedir->matchStart( $s->cur_text ) ) ) {
133 if ( preg_match( "/\\[\\[([^\\]\\|]+)[\\]\\|]/",
134 $s->cur_text, $m ) ) {
135 $rt = Title::newFromText( $m[1] );
136
137 # Gotta hand redirects to special pages differently:
138 # Fill the HTTP response "Location" header and ignore
139 # the rest of the page we're on.
140
141 if ( $rt->getInterwiki() != "" ) {
142 $wgOut->redirect( $rt->getFullURL() ) ;
143 return;
144 }
145 if ( $rt->getNamespace() == Namespace::getSpecial() ) {
146 $wgOut->redirect( wfLocalUrl(
147 $rt->getPrefixedURL() ) );
148 return;
149 }
150 $rid = $rt->getArticleID();
151 if ( 0 != $rid ) {
152 $sql = "SELECT cur_text,cur_timestamp,cur_user," .
153 "cur_counter,cur_restrictions,cur_touched FROM cur WHERE cur_id={$rid}";
154 $res = wfQuery( $sql, DB_READ, $fname );
155
156 if ( 0 != wfNumRows( $res ) ) {
157 $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
158 $this->mTitle = $rt;
159 $s = wfFetchObject( $res );
160 }
161 }
162 }
163 }
164
165 $this->mContent = $s->cur_text;
166 $this->mUser = $s->cur_user;
167 $this->mCounter = $s->cur_counter;
168 $this->mTimestamp = $s->cur_timestamp;
169 $this->mTouched = $s->cur_touched;
170 $this->mTitle->mRestrictions = explode( ",", trim( $s->cur_restrictions ) );
171 $this->mTitle->mRestrictionsLoaded = true;
172 wfFreeResult( $res );
173 } else { # oldid set, retrieve historical version
174 $sql = "SELECT old_text,old_timestamp,old_user FROM old " .
175 "WHERE old_id={$oldid}";
176 $res = wfQuery( $sql, DB_READ, $fname );
177 if ( 0 == wfNumRows( $res ) ) { return; }
178
179 $s = wfFetchObject( $res );
180 $this->mContent = $s->old_text;
181 $this->mUser = $s->old_user;
182 $this->mCounter = 0;
183 $this->mTimestamp = $s->old_timestamp;
184 wfFreeResult( $res );
185 }
186 $this->mContentLoaded = true;
187 }
188
189 function getID() { return $this->mTitle->getArticleID(); }
190
191 function getCount()
192 {
193 if ( -1 == $this->mCounter ) {
194 $id = $this->getID();
195 $this->mCounter = wfGetSQL( "cur", "cur_counter", "cur_id={$id}" );
196 }
197 return $this->mCounter;
198 }
199
200 # Would the given text make this article a "good" article (i.e.,
201 # suitable for including in the article count)?
202
203 function isCountable( $text )
204 {
205 global $wgUseCommaCount, $wgMwRedir;
206
207 if ( 0 != $this->mTitle->getNamespace() ) { return 0; }
208 if ( $wgMwRedir->matchStart( $text ) ) { return 0; }
209 $token = ($wgUseCommaCount ? "," : "[[" );
210 if ( false === strstr( $text, $token ) ) { return 0; }
211 return 1;
212 }
213
214 # Load the field related to the last edit time of the article.
215 # This isn't necessary for all uses, so it's only done if needed.
216
217 /* private */ function loadLastEdit()
218 {
219 global $wgOut;
220 if ( -1 != $this->mUser ) return;
221
222 $sql = "SELECT cur_user,cur_user_text,cur_timestamp," .
223 "cur_comment,cur_minor_edit FROM cur WHERE " .
224 "cur_id=" . $this->getID();
225 $res = wfQuery( $sql, DB_READ, "Article::loadLastEdit" );
226
227 if ( wfNumRows( $res ) > 0 ) {
228 $s = wfFetchObject( $res );
229 $this->mUser = $s->cur_user;
230 $this->mUserText = $s->cur_user_text;
231 $this->mTimestamp = $s->cur_timestamp;
232 $this->mComment = $s->cur_comment;
233 $this->mMinorEdit = $s->cur_minor_edit;
234 }
235 }
236
237 function getTimestamp()
238 {
239 $this->loadLastEdit();
240 return $this->mTimestamp;
241 }
242
243 function getUser()
244 {
245 $this->loadLastEdit();
246 return $this->mUser;
247 }
248
249 function getUserText()
250 {
251 $this->loadLastEdit();
252 return $this->mUserText;
253 }
254
255 function getComment()
256 {
257 $this->loadLastEdit();
258 return $this->mComment;
259 }
260
261 function getMinorEdit()
262 {
263 $this->loadLastEdit();
264 return $this->mMinorEdit;
265 }
266
267 # This is the default action of the script: just view the page of
268 # the given title.
269
270 function view()
271 {
272 global $wgUser, $wgOut, $wgLang;
273 global $oldid, $diff; # From query
274 global $wgLinkCache, $IP;
275 $fname = "Article::view";
276 wfProfileIn( $fname );
277
278 $wgOut->setArticleFlag( true );
279 $wgOut->setRobotpolicy( "index,follow" );
280
281 # If we got diff and oldid in the query, we want to see a
282 # diff page instead of the article.
283
284 if ( isset( $diff ) ) {
285 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
286 $de = new DifferenceEngine( $oldid, $diff );
287 $de->showDiffPage();
288 wfProfileOut( $fname );
289 return;
290 }
291
292 if ( !isset( $oldid ) ) {
293 if( $this->checkTouched() ) {
294 $wgOut->checkLastModified( $this->mTouched );
295 $this->tryFileCache();
296 }
297 }
298
299 $text = $this->getContent(); # May change mTitle
300 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
301 $wgOut->setHTMLTitle( $this->mTitle->getPrefixedText() .
302 " - " . wfMsg( "wikititlesuffix" ) );
303
304 # We're looking at an old revision
305
306 if ( $oldid ) {
307 $this->setOldSubtitle();
308 $wgOut->setRobotpolicy( "noindex,follow" );
309 }
310 if ( "" != $this->mRedirectedFrom ) {
311 $sk = $wgUser->getSkin();
312 $redir = $sk->makeKnownLink( $this->mRedirectedFrom, "",
313 "redirect=no" );
314 $s = wfMsg( "redirectedfrom", $redir );
315 $wgOut->setSubtitle( $s );
316 }
317 $wgLinkCache->preFill( $this->mTitle );
318 $wgOut->addWikiText( $text );
319
320 $this->viewUpdates();
321 wfProfileOut( $fname );
322 }
323
324 # Theoretically we could defer these whole insert and update
325 # functions for after display, but that's taking a big leap
326 # of faith, and we want to be able to report database
327 # errors at some point.
328
329 /* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis )
330 {
331 global $wgOut, $wgUser, $wgLinkCache, $wgMwRedir;
332 global $wgEnablePersistentLC;
333
334 $fname = "Article::insertNewArticle";
335
336 $ns = $this->mTitle->getNamespace();
337 $ttl = $this->mTitle->getDBkey();
338 $text = $this->preSaveTransform( $text );
339 if ( $wgMwRedir->matchStart( $text ) ) { $redir = 1; }
340 else { $redir = 0; }
341
342 $now = wfTimestampNow();
343 $won = wfInvertTimestamp( $now );
344 wfSeedRandom();
345 $rand = number_format( mt_rand() / mt_getrandmax(), 12, ".", "" );
346 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
347 "cur_comment,cur_user,cur_timestamp,cur_minor_edit,cur_counter," .
348 "cur_restrictions,cur_user_text,cur_is_redirect," .
349 "cur_is_new,cur_random,cur_touched,inverse_timestamp) VALUES ({$ns},'" . wfStrencode( $ttl ) . "', '" .
350 wfStrencode( $text ) . "', '" .
351 wfStrencode( $summary ) . "', '" .
352 $wgUser->getID() . "', '{$now}', " .
353 ( $isminor ? 1 : 0 ) . ", 0, '', '" .
354 wfStrencode( $wgUser->getName() ) . "', $redir, 1, $rand, '{$now}', '{$won}')";
355 $res = wfQuery( $sql, DB_WRITE, $fname );
356
357 $newid = wfInsertId();
358 $this->mTitle->resetArticleID( $newid );
359
360 if ( $wgEnablePersistentLC ) {
361 // Purge related entries in links cache on new page, to heal broken links
362 $ptitle = wfStrencode( $ttl );
363 wfQuery("DELETE linkscc FROM linkscc,brokenlinks ".
364 "WHERE lcc_pageid=bl_from AND bl_to='{$ptitle}'", DB_WRITE);
365 }
366
367 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
368 "rc_namespace,rc_title,rc_new,rc_minor,rc_cur_id,rc_user," .
369 "rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid,rc_bot) VALUES (" .
370 "'{$now}','{$now}',{$ns},'" . wfStrencode( $ttl ) . "',1," .
371 ( $isminor ? 1 : 0 ) . ",{$newid}," . $wgUser->getID() . ",'" .
372 wfStrencode( $wgUser->getName() ) . "','" .
373 wfStrencode( $summary ) . "',0,0," .
374 ( $wgUser->isBot() ? 1 : 0 ) . ")";
375 wfQuery( $sql, DB_WRITE, $fname );
376 if ($watchthis) {
377 if(!$this->mTitle->userIsWatching()) $this->watch();
378 } else {
379 if ( $this->mTitle->userIsWatching() ) {
380 $this->unwatch();
381 }
382 }
383
384 # The talk page isn't in the regular link tables, so we need to update manually:
385 $talkns = $ns ^ 1; # talk -> normal; normal -> talk
386 $sql = "UPDATE cur set cur_touched='$now' WHERE cur_namespace=$talkns AND cur_title='" . wfStrencode( $ttl ) . "'";
387 wfQuery( $sql, DB_WRITE );
388
389 $this->showArticle( $text, wfMsg( "newarticle" ) );
390 }
391
392 function updateArticle( $text, $summary, $minor, $watchthis, $section = "")
393 {
394 global $wgOut, $wgUser, $wgLinkCache;
395 global $wgDBtransactions, $wgMwRedir;
396 $fname = "Article::updateArticle";
397
398 $this->loadLastEdit();
399
400 // insert updated section into old text if we have only edited part
401 // of the article
402 if ($section != "") {
403 $oldtext=$this->getContent();
404 if($section=="new") {
405 if($summary) $subject="== {$summary} ==\n\n";
406 $text=$oldtext."\n\n".$subject.$text;
407 } else {
408 $secs=preg_split("/(^=+.*?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)/mi",
409 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE);
410 $secs[$section*2]=$text."\n\n"; // replace with edited
411 if($section) { $secs[$section*2-1]=""; } // erase old headline
412 $text=join("",$secs);
413 }
414 }
415 if ( $this->mMinorEdit ) { $me1 = 1; } else { $me1 = 0; }
416 if ( $minor ) { $me2 = 1; } else { $me2 = 0; }
417 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ")[^\\n]+)/i", $text, $m ) ) {
418 $redir = 1;
419 $text = $m[1] . "\n"; # Remove all content but redirect
420 }
421 else { $redir = 0; }
422
423 $text = $this->preSaveTransform( $text );
424
425 # Update article, but only if changed.
426
427 if( $wgDBtransactions ) {
428 $sql = "BEGIN";
429 wfQuery( $sql, DB_WRITE );
430 }
431 $oldtext = $this->getContent( true );
432
433 if ( 0 != strcmp( $text, $oldtext ) ) {
434 $this->mCountAdjustment = $this->isCountable( $text )
435 - $this->isCountable( $oldtext );
436
437 $now = wfTimestampNow();
438 $won = wfInvertTimestamp( $now );
439 $sql = "UPDATE cur SET cur_text='" . wfStrencode( $text ) .
440 "',cur_comment='" . wfStrencode( $summary ) .
441 "',cur_minor_edit={$me2}, cur_user=" . $wgUser->getID() .
442 ",cur_timestamp='{$now}',cur_user_text='" .
443 wfStrencode( $wgUser->getName() ) .
444 "',cur_is_redirect={$redir}, cur_is_new=0, cur_touched='{$now}', inverse_timestamp='{$won}' " .
445 "WHERE cur_id=" . $this->getID() .
446 " AND cur_timestamp='" . $this->getTimestamp() . "'";
447 $res = wfQuery( $sql, DB_WRITE, $fname );
448
449 if( wfAffectedRows() == 0 ) {
450 /* Belated edit conflict! Run away!! */
451 return false;
452 }
453
454 $sql = "INSERT INTO old (old_namespace,old_title,old_text," .
455 "old_comment,old_user,old_user_text,old_timestamp," .
456 "old_minor_edit,inverse_timestamp) VALUES (" .
457 $this->mTitle->getNamespace() . ", '" .
458 wfStrencode( $this->mTitle->getDBkey() ) . "', '" .
459 wfStrencode( $oldtext ) . "', '" .
460 wfStrencode( $this->getComment() ) . "', " .
461 $this->getUser() . ", '" .
462 wfStrencode( $this->getUserText() ) . "', '" .
463 $this->getTimestamp() . "', " . $me1 . ", '" .
464 wfInvertTimestamp( $this->getTimestamp() ) . "')";
465 $res = wfQuery( $sql, DB_WRITE, $fname );
466 $oldid = wfInsertID( $res );
467
468 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
469 "rc_namespace,rc_title,rc_new,rc_minor,rc_bot,rc_cur_id,rc_user," .
470 "rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid) VALUES (" .
471 "'{$now}','{$now}'," . $this->mTitle->getNamespace() . ",'" .
472 wfStrencode( $this->mTitle->getDBkey() ) . "',0,{$me2}," .
473 ( $wgUser->isBot() ? 1 : 0 ) . "," .
474 $this->getID() . "," . $wgUser->getID() . ",'" .
475 wfStrencode( $wgUser->getName() ) . "','" .
476 wfStrencode( $summary ) . "',0,{$oldid})";
477 wfQuery( $sql, DB_WRITE, $fname );
478
479 $sql = "UPDATE recentchanges SET rc_this_oldid={$oldid} " .
480 "WHERE rc_namespace=" . $this->mTitle->getNamespace() . " AND " .
481 "rc_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' AND " .
482 "rc_timestamp='" . $this->getTimestamp() . "'";
483 wfQuery( $sql, DB_WRITE, $fname );
484
485 $sql = "UPDATE recentchanges SET rc_cur_time='{$now}' " .
486 "WHERE rc_cur_id=" . $this->getID();
487 wfQuery( $sql, DB_WRITE, $fname );
488
489 if ( $wgEnablePersistentLC ) {
490
491 // Purge link cache for this page
492 $pageid=$this->getID();
493 wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pageid}'", DB_WRITE);
494
495 // This next query just makes sure stub colored links to this page
496 // are updated correctly (I think). If performance is more important
497 // than real-time updating of stub links, we really should skip
498 // this query.
499 wfQuery("DELETE linkscc FROM linkscc,links ".
500 "WHERE lcc_title=links.l_from AND l_to={$pageid}", DB_WRITE);
501 }
502
503 }
504 if( $wgDBtransactions ) {
505 $sql = "COMMIT";
506 wfQuery( $sql, DB_WRITE );
507 }
508
509 if ($watchthis) {
510 if (!$this->mTitle->userIsWatching()) $this->watch();
511 } else {
512 if ( $this->mTitle->userIsWatching() ) {
513 $this->unwatch();
514 }
515 }
516
517 $this->showArticle( $text, wfMsg( "updated" ) );
518 return true;
519 }
520
521 # After we've either updated or inserted the article, update
522 # the link tables and redirect to the new page.
523
524 function showArticle( $text, $subtitle )
525 {
526 global $wgOut, $wgUser, $wgLinkCache, $wgUseBetterLinksUpdate;
527 global $wgMwRedir;
528
529 $wgLinkCache = new LinkCache();
530
531 # Get old version of link table to allow incremental link updates
532 if ( $wgUseBetterLinksUpdate ) {
533 $wgLinkCache->preFill( $this->mTitle );
534 $wgLinkCache->clear();
535 }
536
537 # Now update the link cache by parsing the text
538 $wgOut = new OutputPage();
539 $wgOut->addWikiText( $text );
540
541 $this->editUpdates( $text );
542 if( $wgMwRedir->matchStart( $text ) )
543 $r = "redirect=no";
544 else
545 $r = "";
546 $wgOut->redirect( wfLocalUrl( $this->mTitle->getPrefixedURL(), $r ) );
547 }
548
549 # Add this page to my watchlist
550
551 function watch( $add = true )
552 {
553 global $wgUser, $wgOut, $wgLang;
554 global $wgDeferredUpdateList;
555
556 if ( 0 == $wgUser->getID() ) {
557 $wgOut->errorpage( "watchnologin", "watchnologintext" );
558 return;
559 }
560 if ( wfReadOnly() ) {
561 $wgOut->readOnlyPage();
562 return;
563 }
564 if( $add )
565 $wgUser->addWatch( $this->mTitle );
566 else
567 $wgUser->removeWatch( $this->mTitle );
568
569 $wgOut->setPagetitle( wfMsg( $add ? "addedwatch" : "removedwatch" ) );
570 $wgOut->setRobotpolicy( "noindex,follow" );
571
572 $sk = $wgUser->getSkin() ;
573 $link = $sk->makeKnownLink ( $this->mTitle->getPrefixedText() ) ;
574
575 if($add)
576 $text = wfMsg( "addedwatchtext", $link );
577 else
578 $text = wfMsg( "removedwatchtext", $link );
579 $wgOut->addHTML( $text );
580
581 $up = new UserUpdate();
582 array_push( $wgDeferredUpdateList, $up );
583
584 $wgOut->returnToMain( false );
585 }
586
587 function unwatch()
588 {
589 $this->watch( false );
590 }
591
592 # This shares a lot of issues (and code) with Recent Changes
593
594 function history()
595 {
596 global $wgUser, $wgOut, $wgLang, $offset, $limit;
597
598 # If page hasn't changed, client can cache this
599
600 $wgOut->checkLastModified( $this->getTimestamp() );
601 $fname = "Article::history";
602 wfProfileIn( $fname );
603
604 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
605 $wgOut->setSubtitle( wfMsg( "revhistory" ) );
606 $wgOut->setArticleFlag( false );
607 $wgOut->setRobotpolicy( "noindex,nofollow" );
608
609 if( $this->mTitle->getArticleID() == 0 ) {
610 $wgOut->addHTML( wfMsg( "nohistory" ) );
611 wfProfileOut( $fname );
612 return;
613 }
614
615 $offset = (int)$offset;
616 $limit = (int)$limit;
617 if( $limit == 0 ) $limit = 50;
618 $namespace = $this->mTitle->getNamespace();
619 $title = $this->mTitle->getText();
620 $sql = "SELECT old_id,old_user," .
621 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
622 "FROM old USE INDEX (name_title_timestamp) " .
623 "WHERE old_namespace={$namespace} AND " .
624 "old_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " .
625 "ORDER BY inverse_timestamp LIMIT $offset, $limit";
626 $res = wfQuery( $sql, DB_READ, "Article::history" );
627
628 $revs = wfNumRows( $res );
629 if( $this->mTitle->getArticleID() == 0 ) {
630 $wgOut->addHTML( wfMsg( "nohistory" ) );
631 wfProfileOut( $fname );
632 return;
633 }
634
635 $sk = $wgUser->getSkin();
636 $numbar = wfViewPrevNext(
637 $offset, $limit,
638 $this->mTitle->getPrefixedText(),
639 "action=history" );
640 $s = $numbar;
641 $s .= $sk->beginHistoryList();
642
643 if($offset == 0 )
644 $s .= $sk->historyLine( $this->getTimestamp(), $this->getUser(),
645 $this->getUserText(), $namespace,
646 $title, 0, $this->getComment(),
647 ( $this->getMinorEdit() > 0 ) );
648
649 $revs = wfNumRows( $res );
650 while ( $line = wfFetchObject( $res ) ) {
651 $s .= $sk->historyLine( $line->old_timestamp, $line->old_user,
652 $line->old_user_text, $namespace,
653 $title, $line->old_id,
654 $line->old_comment, ( $line->old_minor_edit > 0 ) );
655 }
656 $s .= $sk->endHistoryList();
657 $s .= $numbar;
658 $wgOut->addHTML( $s );
659 wfProfileOut( $fname );
660 }
661
662 function protect( $limit = "sysop" )
663 {
664 global $wgUser, $wgOut;
665
666 if ( ! $wgUser->isSysop() ) {
667 $wgOut->sysopRequired();
668 return;
669 }
670 if ( wfReadOnly() ) {
671 $wgOut->readOnlyPage();
672 return;
673 }
674 $id = $this->mTitle->getArticleID();
675 if ( 0 == $id ) {
676 $wgOut->fatalEror( wfMsg( "badarticleerror" ) );
677 return;
678 }
679 $sql = "UPDATE cur SET cur_touched='" . wfTimestampNow() . "'," .
680 "cur_restrictions='{$limit}' WHERE cur_id={$id}";
681 wfQuery( $sql, DB_WRITE, "Article::protect" );
682
683 $log = new LogPage( wfMsg( "protectlogpage" ), wfMsg( "protectlogtext" ) );
684 if ( $limit === "" ) {
685 $log->addEntry( wfMsg( "unprotectedarticle", $this->mTitle->getPrefixedText() ), "" );
686 } else {
687 $log->addEntry( wfMsg( "protectedarticle", $this->mTitle->getPrefixedText() ), "" );
688 }
689 $wgOut->redirect( wfLocalUrl( $this->mTitle->getPrefixedURL() ) );
690 }
691
692 function unprotect()
693 {
694 return $this->protect( "" );
695 }
696
697 function delete()
698 {
699 global $wgUser, $wgOut;
700 global $wpConfirm, $wpReason, $image, $oldimage;
701
702 # This code desperately needs to be totally rewritten
703
704 if ( ( ! $wgUser->isSysop() ) ) {
705 $wgOut->sysopRequired();
706 return;
707 }
708 if ( wfReadOnly() ) {
709 $wgOut->readOnlyPage();
710 return;
711 }
712
713 # Better double-check that it hasn't been deleted yet!
714 $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
715 if ( ( "" == trim( $this->mTitle->getText() ) )
716 or ( $this->mTitle->getArticleId() == 0 ) ) {
717 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
718 return;
719 }
720
721 if ( $_POST["wpConfirm"] ) {
722 $this->doDelete();
723 return;
724 }
725
726 # determine whether this page has earlier revisions
727 # and insert a warning if it does
728 # we select the text because it might be useful below
729 $ns = $this->mTitle->getNamespace();
730 $title = $this->mTitle->getDBkey();
731 $etitle = wfStrencode( $title );
732 $sql = "SELECT old_text FROM old WHERE old_namespace=$ns and old_title='$etitle' ORDER BY inverse_timestamp LIMIT 1";
733 $res = wfQuery( $sql, DB_READ, $fname );
734 if( ($old=wfFetchObject($res)) && !$wpConfirm ) {
735 $skin=$wgUser->getSkin();
736 $wgOut->addHTML("<B>".wfMsg("historywarning"));
737 $wgOut->addHTML( $skin->historyLink() ."</B><P>");
738 }
739
740 $sql="SELECT cur_text FROM cur WHERE cur_namespace=$ns and cur_title='$etitle'";
741 $res=wfQuery($sql, DB_READ, $fname);
742 if( ($s=wfFetchObject($res))) {
743
744 # if this is a mini-text, we can paste part of it into the deletion reason
745
746 #if this is empty, an earlier revision may contain "useful" text
747 if($s->cur_text!="") {
748 $text=$s->cur_text;
749 } else {
750 if($old) {
751 $text=$old->old_text;
752 $blanked=1;
753 }
754
755 }
756
757 $length=strlen($text);
758
759 # this should not happen, since it is not possible to store an empty, new
760 # page. Let's insert a standard text in case it does, though
761 if($length==0 && !$wpReason) { $wpReason=wfmsg("exblank");}
762
763
764 if($length < 500 && !$wpReason) {
765
766 # comment field=255, let's grep the first 150 to have some user
767 # space left
768 $text=substr($text,0,150);
769 # let's strip out newlines and HTML tags
770 $text=preg_replace("/\"/","'",$text);
771 $text=preg_replace("/\</","&lt;",$text);
772 $text=preg_replace("/\>/","&gt;",$text);
773 $text=preg_replace("/[\n\r]/","",$text);
774 if(!$blanked) {
775 $wpReason=wfMsg("excontent"). " '".$text;
776 } else {
777 $wpReason=wfMsg("exbeforeblank") . " '".$text;
778 }
779 if($length>150) { $wpReason .= "..."; } # we've only pasted part of the text
780 $wpReason.="'";
781 }
782 }
783
784 return $this->confirmDelete();
785 }
786
787 function confirmDelete( $par = "" )
788 {
789 global $wgOut;
790 global $wpReason;
791
792 wfDebug( "Article::confirmDelete\n" );
793
794 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
795 $wgOut->setSubtitle( wfMsg( "deletesub", $sub ) );
796 $wgOut->setRobotpolicy( "noindex,nofollow" );
797 $wgOut->addWikiText( wfMsg( "confirmdeletetext" ) );
798
799 $t = $this->mTitle->getPrefixedURL();
800
801 $formaction = wfEscapeHTML( wfLocalUrl( $t, "action=delete" . $par ) );
802 $confirm = wfMsg( "confirm" );
803 $check = wfMsg( "confirmcheck" );
804 $delcom = wfMsg( "deletecomment" );
805
806 $wgOut->addHTML( "
807 <form id=\"deleteconfirm\" method=\"post\" action=\"{$formaction}\">
808 <table border=0><tr><td align=right>
809 {$delcom}:</td><td align=left>
810 <input type=text size=60 name=\"wpReason\" value=\"" . htmlspecialchars( $wpReason ) . "\">
811 </td></tr><tr><td>&nbsp;</td></tr>
812 <tr><td align=right>
813 <input type=checkbox name=\"wpConfirm\" value='1' id=\"wpConfirm\">
814 </td><td><label for=\"wpConfirm\">{$check}</label></td>
815 </tr><tr><td>&nbsp;</td><td>
816 <input type=submit name=\"wpConfirmB\" value=\"{$confirm}\">
817 </td></tr></table></form>\n" );
818
819 $wgOut->returnToMain( false );
820 }
821
822 function doDelete()
823 {
824 global $wgOut, $wgUser, $wgLang;
825 global $wpReason;
826 $fname = "Article::doDelete";
827 wfDebug( "$fname\n" );
828
829 $this->doDeleteArticle( $this->mTitle );
830 $deleted = $this->mTitle->getPrefixedText();
831
832 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
833 $wgOut->setRobotpolicy( "noindex,nofollow" );
834
835 $sk = $wgUser->getSkin();
836 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
837 Namespace::getWikipedia() ) .
838 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
839
840 $text = wfMsg( "deletedtext", $deleted, $loglink );
841
842 $wgOut->addHTML( "<p>" . $text );
843 $wgOut->returnToMain( false );
844 }
845
846 function doDeleteArticle( $title )
847 {
848 global $wgUser, $wgOut, $wgLang, $wpReason, $wgDeferredUpdateList;
849
850 $fname = "Article::doDeleteArticle";
851 wfDebug( "$fname\n" );
852
853 $ns = $title->getNamespace();
854 $t = wfStrencode( $title->getDBkey() );
855 $id = $title->getArticleID();
856
857 if ( "" == $t ) {
858 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
859 return;
860 }
861
862 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
863 array_push( $wgDeferredUpdateList, $u );
864
865 # Move article and history to the "archive" table
866 $sql = "INSERT INTO archive (ar_namespace,ar_title,ar_text," .
867 "ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit," .
868 "ar_flags) SELECT cur_namespace,cur_title,cur_text,cur_comment," .
869 "cur_user,cur_user_text,cur_timestamp,cur_minor_edit,0 FROM cur " .
870 "WHERE cur_namespace={$ns} AND cur_title='{$t}'";
871 wfQuery( $sql, DB_WRITE, $fname );
872
873 $sql = "INSERT INTO archive (ar_namespace,ar_title,ar_text," .
874 "ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit," .
875 "ar_flags) SELECT old_namespace,old_title,old_text,old_comment," .
876 "old_user,old_user_text,old_timestamp,old_minor_edit,old_flags " .
877 "FROM old WHERE old_namespace={$ns} AND old_title='{$t}'";
878 wfQuery( $sql, DB_WRITE, $fname );
879
880 # Now that it's safely backed up, delete it
881
882 $sql = "DELETE FROM cur WHERE cur_namespace={$ns} AND " .
883 "cur_title='{$t}'";
884 wfQuery( $sql, DB_WRITE, $fname );
885
886 $sql = "DELETE FROM old WHERE old_namespace={$ns} AND " .
887 "old_title='{$t}'";
888 wfQuery( $sql, DB_WRITE, $fname );
889
890 $sql = "DELETE FROM recentchanges WHERE rc_namespace={$ns} AND " .
891 "rc_title='{$t}'";
892 wfQuery( $sql, DB_WRITE, $fname );
893
894 # Finally, clean up the link tables
895
896 if ( 0 != $id ) {
897
898 $t = wfStrencode( $title->getPrefixedDBkey() );
899
900 if ( $wgEnablePersistentLC ) {
901 // Purge related entries in links cache on delete,
902 wfQuery("DELETE linkscc FROM linkscc,links ".
903 "WHERE lcc_title=links.l_from AND l_to={$id}", DB_WRITE);
904 wfQuery("DELETE FROM linkscc WHERE lcc_title='{$t}'", DB_WRITE);
905 }
906
907 $sql = "SELECT l_from FROM links WHERE l_to={$id}";
908 $res = wfQuery( $sql, DB_READ, $fname );
909
910 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
911 $now = wfTimestampNow();
912 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
913 $first = true;
914
915 while ( $s = wfFetchObject( $res ) ) {
916 $nt = Title::newFromDBkey( $s->l_from );
917 $lid = $nt->getArticleID();
918
919 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
920 $first = false;
921 $sql .= "({$lid},'{$t}')";
922 $sql2 .= "{$lid}";
923 }
924 $sql2 .= ")";
925 if ( ! $first ) {
926 wfQuery( $sql, DB_WRITE, $fname );
927 wfQuery( $sql2, DB_WRITE, $fname );
928 }
929 wfFreeResult( $res );
930
931 $sql = "DELETE FROM links WHERE l_to={$id}";
932 wfQuery( $sql, DB_WRITE, $fname );
933
934 $sql = "DELETE FROM links WHERE l_from='{$t}'";
935 wfQuery( $sql, DB_WRITE, $fname );
936
937 $sql = "DELETE FROM imagelinks WHERE il_from='{$t}'";
938 wfQuery( $sql, DB_WRITE, $fname );
939
940 $sql = "DELETE FROM brokenlinks WHERE bl_from={$id}";
941 wfQuery( $sql, DB_WRITE, $fname );
942 }
943
944 $log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) );
945 $art = $title->getPrefixedText();
946 $wpReason = wfCleanQueryVar( $wpReason );
947 $log->addEntry( wfMsg( "deletedarticle", $art ), $wpReason );
948
949 # Clear the cached article id so the interface doesn't act like we exist
950 $this->mTitle->resetArticleID( 0 );
951 $this->mTitle->mArticleID = 0;
952 }
953
954 function rollback()
955 {
956 global $wgUser, $wgLang, $wgOut, $from;
957
958 if ( ! $wgUser->isSysop() ) {
959 $wgOut->sysopRequired();
960 return;
961 }
962
963 # Replace all this user's current edits with the next one down
964 $tt = wfStrencode( $this->mTitle->getDBKey() );
965 $n = $this->mTitle->getNamespace();
966
967 # Get the last editor
968 $sql = "SELECT cur_id,cur_user,cur_user_text,cur_comment FROM cur WHERE cur_title='{$tt}' AND cur_namespace={$n}";
969 $res = wfQuery( $sql, DB_READ );
970 if( ($x = wfNumRows( $res )) != 1 ) {
971 # Something wrong
972 $wgOut->addHTML( wfMsg( "notanarticle" ) );
973 return;
974 }
975 $s = wfFetchObject( $res );
976 $ut = wfStrencode( $s->cur_user_text );
977 $uid = $s->cur_user;
978 $pid = $s->cur_id;
979
980 $from = str_replace( '_', ' ', wfCleanQueryVar( $from ) );
981 if( $from != $s->cur_user_text ) {
982 $wgOut->setPageTitle(wfmsg("rollbackfailed"));
983 $wgOut->addWikiText( wfMsg( "alreadyrolled",
984 htmlspecialchars( $this->mTitle->getPrefixedText()),
985 htmlspecialchars( $from ),
986 htmlspecialchars( $s->cur_user_text ) ) );
987 if($s->cur_comment != "") {
988 $wgOut->addHTML(
989 wfMsg("editcomment",
990 htmlspecialchars( $s->cur_comment ) ) );
991 }
992 return;
993 }
994
995 # Get the last edit not by this guy
996 $sql = "SELECT old_text,old_user,old_user_text
997 FROM old USE INDEX (name_title_timestamp)
998 WHERE old_namespace={$n} AND old_title='{$tt}'
999 AND (old_user <> {$uid} OR old_user_text <> '{$ut}')
1000 ORDER BY inverse_timestamp LIMIT 1";
1001 $res = wfQuery( $sql, DB_READ );
1002 if( wfNumRows( $res ) != 1 ) {
1003 # Something wrong
1004 $wgOut->setPageTitle(wfMsg("rollbackfailed"));
1005 $wgOut->addHTML( wfMsg( "cantrollback" ) );
1006 return;
1007 }
1008 $s = wfFetchObject( $res );
1009
1010 # Save it!
1011 $newcomment = wfMsg( "revertpage", $s->old_user_text );
1012 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
1013 $wgOut->setRobotpolicy( "noindex,nofollow" );
1014 $wgOut->addHTML( "<h2>" . $newcomment . "</h2>\n<hr>\n" );
1015 $this->updateArticle( $s->old_text, $newcomment, 1, $this->mTitle->userIsWatching() );
1016
1017 $wgOut->returnToMain( false );
1018 }
1019
1020
1021 # Do standard deferred updates after page view
1022
1023 /* private */ function viewUpdates()
1024 {
1025 global $wgDeferredUpdateList;
1026
1027 if ( 0 != $this->getID() ) {
1028 global $wgDisableCounters;
1029 if( !$wgDisableCounters ) {
1030 $u = new ViewCountUpdate( $this->getID() );
1031 array_push( $wgDeferredUpdateList, $u );
1032 $u = new SiteStatsUpdate( 1, 0, 0 );
1033 array_push( $wgDeferredUpdateList, $u );
1034 }
1035 $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
1036 $this->mTitle->getDBkey() );
1037 array_push( $wgDeferredUpdateList, $u );
1038 }
1039 }
1040
1041 # Do standard deferred updates after page edit.
1042 # Every 1000th edit, prune the recent changes table.
1043
1044 /* private */ function editUpdates( $text )
1045 {
1046 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1047
1048 wfSeedRandom();
1049 if ( 0 == mt_rand( 0, 999 ) ) {
1050 $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
1051 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
1052 wfQuery( $sql, DB_WRITE );
1053 }
1054 $id = $this->getID();
1055 $title = $this->mTitle->getPrefixedDBkey();
1056 $adj = $this->mCountAdjustment;
1057
1058 if ( 0 != $id ) {
1059 $u = new LinksUpdate( $id, $title );
1060 array_push( $wgDeferredUpdateList, $u );
1061 $u = new SiteStatsUpdate( 0, 1, $adj );
1062 array_push( $wgDeferredUpdateList, $u );
1063 $u = new SearchUpdate( $id, $title, $text );
1064 array_push( $wgDeferredUpdateList, $u );
1065
1066 $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(),
1067 $this->mTitle->getDBkey() );
1068 array_push( $wgDeferredUpdateList, $u );
1069
1070 if ( $this->getNamespace == NS_MEDIAWIKI ) {
1071 $messageCache = $wgMemc->get( "$wgDBname:messages" );
1072 if (!$messageCache) {
1073 $messageCache = wfLoadAllMessages();
1074 }
1075 $messageCache[$title] = $text;
1076 $wgMemc->set( "$wgDBname:messages" );
1077 }
1078 }
1079 }
1080
1081 /* private */ function setOldSubtitle()
1082 {
1083 global $wgLang, $wgOut;
1084
1085 $td = $wgLang->timeanddate( $this->mTimestamp, true );
1086 $r = wfMsg( "revisionasof", $td );
1087 $wgOut->setSubtitle( "({$r})" );
1088 }
1089
1090 # This function is called right before saving the wikitext,
1091 # so we can do things like signatures and links-in-context.
1092
1093 function preSaveTransform( $text )
1094 {
1095 $s = "";
1096 while ( "" != $text ) {
1097 $p = preg_split( "/<\\s*nowiki\\s*>/i", $text, 2 );
1098 $s .= $this->pstPass2( $p[0] );
1099
1100 if ( ( count( $p ) < 2 ) || ( "" == $p[1] ) ) { $text = ""; }
1101 else {
1102 $q = preg_split( "/<\\/\\s*nowiki\\s*>/i", $p[1], 2 );
1103 $s .= "<nowiki>{$q[0]}</nowiki>";
1104 $text = $q[1];
1105 }
1106 }
1107 return rtrim( $s );
1108 }
1109
1110 /* private */ function pstPass2( $text )
1111 {
1112 global $wgUser, $wgLang, $wgLocaltimezone;
1113
1114 # Signatures
1115 #
1116 $n = $wgUser->getName();
1117 $k = $wgUser->getOption( "nickname" );
1118 if ( "" == $k ) { $k = $n; }
1119 if(isset($wgLocaltimezone)) {
1120 $oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone");
1121 }
1122 /* Note: this is an ugly timezone hack for the European wikis */
1123 $d = $wgLang->timeanddate( date( "YmdHis" ), false ) .
1124 " (" . date( "T" ) . ")";
1125 if(isset($wgLocaltimezone)) putenv("TZ=$oldtz");
1126
1127 $text = preg_replace( "/~~~~/", "[[" . $wgLang->getNsText(
1128 Namespace::getUser() ) . ":$n|$k]] $d", $text );
1129 $text = preg_replace( "/~~~/", "[[" . $wgLang->getNsText(
1130 Namespace::getUser() ) . ":$n|$k]]", $text );
1131
1132 # Context links: [[|name]] and [[name (context)|]]
1133 #
1134 $tc = "[&;%\\-,.\\(\\)' _0-9A-Za-z\\/:\\x80-\\xff]";
1135 $np = "[&;%\\-,.' _0-9A-Za-z\\/:\\x80-\\xff]"; # No parens
1136 $namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
1137 $conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
1138
1139 $p1 = "/\[\[({$np}+) \\(({$np}+)\\)\\|]]/"; # [[page (context)|]]
1140 $p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]]
1141 $p3 = "/\[\[($namespacechar+):({$np}+)\\|]]/"; # [[namespace:page|]]
1142 $p4 = "/\[\[($namespacechar+):({$np}+) \\(({$np}+)\\)\\|]]/";
1143 # [[ns:page (cont)|]]
1144 $context = "";
1145 $t = $this->mTitle->getText();
1146 if ( preg_match( $conpat, $t, $m ) ) {
1147 $context = $m[2];
1148 }
1149 $text = preg_replace( $p4, "[[\\1:\\2 (\\3)|\\2]]", $text );
1150 $text = preg_replace( $p1, "[[\\1 (\\2)|\\1]]", $text );
1151 $text = preg_replace( $p3, "[[\\1:\\2|\\2]]", $text );
1152
1153 if ( "" == $context ) {
1154 $text = preg_replace( $p2, "[[\\1]]", $text );
1155 } else {
1156 $text = preg_replace( $p2, "[[\\1 ({$context})|\\1]]", $text );
1157 }
1158
1159 # {{SUBST:xxx}} variables
1160 #
1161 $mw =& MagicWord::get( MAG_SUBST );
1162 $text = $mw->substituteCallback( $text, "wfReplaceSubstVar" );
1163
1164 return $text;
1165 }
1166
1167 /* Caching functions */
1168
1169 function tryFileCache() {
1170 static $called = false;
1171 if( $called ) {
1172 wfDebug( " tryFileCache() -- called twice!?\n" );
1173 return;
1174 }
1175 $called = true;
1176 if($this->isFileCacheable()) {
1177 $touched = $this->mTouched;
1178 if( strpos( $this->mContent, "{{" ) !== false ) {
1179 # Expire pages with variable replacements in an hour
1180 $expire = wfUnix2Timestamp( time() - 3600 );
1181 $touched = max( $expire, $touched );
1182 }
1183 $cache = new CacheManager( $this->mTitle );
1184 if($cache->isFileCacheGood( $touched )) {
1185 global $wgOut;
1186 wfDebug( " tryFileCache() - about to load\n" );
1187 $cache->loadFromFileCache();
1188 $wgOut->reportTime(); # For profiling
1189 exit;
1190 } else {
1191 wfDebug( " tryFileCache() - starting buffer\n" );
1192 if($cache->useGzip() && wfClientAcceptsGzip()) {
1193 /* For some reason, adding this header line over in
1194 CacheManager::saveToFileCache() fails on my test
1195 setup at home, though it works on the live install.
1196 Make double-sure... --brion */
1197 header( "Content-Encoding: gzip" );
1198 }
1199 ob_start( array(&$cache, 'saveToFileCache' ) );
1200 }
1201 } else {
1202 wfDebug( " tryFileCache() - not cacheable\n" );
1203 }
1204 }
1205
1206 function isFileCacheable() {
1207 global $wgUser, $wgUseFileCache, $wgShowIPinHeader;
1208 global $action, $oldid, $diff, $redirect, $printable;
1209 return $wgUseFileCache
1210 and (!$wgShowIPinHeader)
1211 and ($this->getID() != 0)
1212 and ($wgUser->getId() == 0)
1213 and (!$wgUser->getNewtalk())
1214 and ($this->mTitle->getNamespace != Namespace::getSpecial())
1215 and ($action == "view")
1216 and (!isset($oldid))
1217 and (!isset($diff))
1218 and (!isset($redirect))
1219 and (!isset($printable))
1220 and (!$this->mRedirectedFrom);
1221 }
1222
1223 function checkTouched() {
1224 $id = $this->getID();
1225 $sql = "SELECT cur_touched,cur_is_redirect FROM cur WHERE cur_id=$id";
1226 $res = wfQuery( $sql, DB_READ, "Article::checkTouched" );
1227 if( $s = wfFetchObject( $res ) ) {
1228 $this->mTouched = $s->cur_touched;
1229 return !$s->cur_is_redirect;
1230 } else {
1231 return false;
1232 }
1233 }
1234 }
1235
1236 function wfReplaceSubstVar( $matches ) {
1237 return wfMsg( $matches[1] );
1238 }
1239
1240 ?>